require(['../config/requireconfig'],function(config){
	//根据需要添加
	require(['zepto','common/mcommon'],function($,com){
        com.init();
		var pageLogic = new PageLogic($,com);
		pageLogic.init();

	});
});
var PageLogic = function($,com){
	return {
		init:function(){
			var _this = this;
			var brandName = com.utils().urlParam("brandName");
			var modelName = com.utils().urlParam("modelName");
			if(!brandName || !modelName){
				com.utils().windowJump();
			}
			$("#brandName").text(com.utils().urlParam("brandName")||"");
			$("#modelName").text(com.utils().urlParam("modelName")||"");
			_this.initVolData();
			_this.initVichileData();
			_this.bindEvent();
		},
		params:function(){
			var _this = this;
			var obj = {
				brandName:com.utils().urlParam("brandName"),
				modelName:com.utils().urlParam("modelName"),
			};
			var volVal = $("#selvol").val();
			if(volVal && volVal != "0"){
				obj["displacementL"] = volVal;
			}
			return obj;
		},
		bindEvent:function(){
			var _this = this;
			$("#selvol").on("change",function(){
				_this.initVichileData();
			});
		},
		initVolData:function(){
			var _this = this;
			com.ajax({
				url:"/getProdDis.json",
				data:_this.params(),
				success:function(res){
					var vols = com.utils().uniqueArr(res.data);
					var html = '<option value="0" >全部</option>';
					$(vols).each(function(){
						html += '<option value="' + this + '" >' + this + '</option>';
					});
					$("#selvol").html(html);
				}
			})
		},
		initVichileData:function(){
			var _this = this;
			com.ajax({
				url:"/getProDdet.json",
				data:_this.params(),
				success:function(res){
					_this.genHtml(res.data);
				}
			});
		},
		genHtml:function(res){
			var html = "";
			if(res){
				$(res).each(function(){
					html += '<li class="vol" tg="' + this.vehicleNo + '" vol="' + com.utils().textIfEmpty(this.displacementL) + '"> ';
					html += '	<div class="vol-line"> ';
					html += '		<span class="vol-line-left">排量（L）</span> ';
					html += '		<span class="vol-line-val">' +  com.utils().textIfEmpty(this.displacementL) + '</span> ';
					html += '	</div> ';
					html += '	<div class="vol-line"> ';
					html += '		<span class="vol-line-left">功率（KW）</span> ';
					html += '		<span class="vol-line-val">' + com.utils().textIfEmpty(this.powerKw) + '</span> ';
					html += '	</div> ';
					html += '	<div class="vol-line"> ';
					html += '		<span class="vol-line-left">发动机编码</span> ';
					html += '		<span class="vol-line-val">' + com.utils().textIfEmpty(this.engineNo) + '</span> ';
					html += '	</div> ';
					html += '		<div class="vol-line"> ';
					html += '		<span class="vol-line-left">车型起始日期</span> ';
					html += '		<span class="vol-line-val">' + com.utils().formatDateYYmm(this.startDate)  + '</span> ';
					html += '	</div> ';
					html += '	<div class="vol-line"> ';
					html += '		<span class="vol-line-left">车型停产日期</span> ';
					html += '		<span class="vol-line-val">' + com.utils().formatDateYYmm(this.stopDate)  + '</span> ';
					html += '	</div> ';
					html += '	<i class="vol-tool"></i> ';
					html += '</li> ';
				});
			}
			$(".vols").html(html);
			$(".vols").find("li").on("click",function(){
				var vehicleNo = $(this).attr("tg");
				var vol = $(this).attr("vol");
				var brandName = com.utils().urlParam("brandName");
				var modelName = com.utils().urlParam("modelName");
				var url = "partsQuery.htm?vehicleNo=" + vehicleNo;
				url += "&v=" + com.utils().randomWord(8);
				com.utils().windowJump(url);
			})
		}
	}
}